package com.newspublish.system.controller;

import com.newspublish.system.entity.system.News;
import com.newspublish.system.service.NewsService;
import com.newspublish.system.utils.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/news")
@Api(tags = "新闻管理")
public class NewsController {

    @Autowired
    private NewsService newsService;

    @ApiOperation(value="获取新闻列表")
    @GetMapping("/getALlNews")
    public Result getAllNews(){
        return newsService.getAllNews();
    }

    @ApiOperation(value="新增新闻")
    @PostMapping("/addNews")
    public Result addNews(News news){
        return newsService.addNews(news);
    }

    @ApiOperation(value="编辑新闻")
    @PostMapping("/uodateNews")
    public Result editNews(News news){
        return newsService.editNews(news);
    }

    @ApiOperation(value="根据分类查询新闻")
    @GetMapping("/getByCategory/{category}")
    public Result getByCategory(@PathVariable("category")String category){
        return newsService.getByCategory(category);
    }


    @ApiOperation(value="点赞新闻")
    @GetMapping("/like/{id}")
    public Result like(@PathVariable("id")Long id){
        return newsService.like(id);
    }

    @ApiOperation(value="根据关注的新闻作者获取新闻作品")
    @GetMapping("/getByAuthor/{author}")
    public Result getByAuthor(@PathVariable("author")String author){
        return newsService.getByAuthor(author);
    }

}
